package app.fugema.shop.main.invoice.model;


import com.base.common.utils.UIUtils;

import java.util.List;

import app.fugema.shop.main.order.model.BaseCouponBean;
import app.fugema.shop.main.order.model.CartItemProductModel;
import app.fugema.shop.main.order.model.SubmitModelResult;
import app.fugema.shop.main.order.model.VatInvoiceBean;
import app.fugema.shop.util.MoneyUtils;

public class SubOrderGoodsBean
{


        /**
         * shopId : 9
         * ShopName : 官方自营1号店-1
         * Freight : 10
         * FreeFreight : 300
         * CartItemModels : [{"skuId":"2767_1531_2796_0","size":"XL","color":"黑色","version":null,"skuDetails":null,"id":2767,"imgUrl":"https://www.fugema.cn:443//Storage/Shop/9/Products/2767/1_100.png","shopName":null,"name":"佳浩厂家冬季新款男士休闲棉服外套韩版潮流时尚纯色立领加厚保暖男士棉衣","price":288,"count":1,"shopId":9,"vshopId":0,"IsSelf":false,"productCode":"DS574","unit":"件","UserCoupons":null,"isDis":false,"ColorAlias":"颜色","SizeAlias":"尺码","VersionAlias":"规格","collpid":0,"IsLimit":false,"ShopBranchId":0,"ShopBranchName":"","IsOpenLadder":false,"FreightTemplateId":220,"fullDiscount":0,"ProductType":0}]
         * UserCoupons : []
         * FullDiscount : 0
         * ShopTotal : 298
         * ShopTotalWithoutFreight : 288
         * UserBonus : null
         * BaseCoupons : []
         * OneCoupons : null
         * freightProductGroup : null
         * IsFreeFreight : false
         * VshopId : 13
         * IsSelf : false
         * ExistShopBranch : false
         * ShopBranchId : 0
         * ShopBranchName :
         * IsOpenLadder : false
         * IsInvoice : true
         * invoiceTpyes : [{"Id":2,"Name":"电子普通发票","Rate":3},{"Id":3,"Name":"增值税发票","Rate":3}]
         * InvoiceDay : 15-18
         */

        private int shopId;
        private String ShopName;
        private int Freight;
        private int FreeFreight;
        private double FullDiscount;
        private double ShopTotal;
        private double ShopTotalWithoutFreight;
        private Object UserBonus;
        private BaseCouponBean OneCoupons;
        private Object freightProductGroup;
        private boolean IsFreeFreight;
        private int VshopId;
        private boolean IsSelf;
        private boolean ExistShopBranch;
        private int ShopBranchId;
        private String ShopBranchName;
        private boolean IsOpenLadder;
        private boolean IsInvoice;
        private String InvoiceDay;
        private List<CartItemProductModel> CartItemModels;
        private List<BaseCouponBean> UserCoupons;
        private List<BaseCouponBean> BaseCoupons;
        private List<SubmitModelResult.ProductsBean.InvoiceTpyesBean> invoiceTpyes;
        // 主动添加一个 参数 remark 用来存储  添加的 备注
        private String remark;
        private InvoiceInfoParams simpleInvoice;

        public int getShopId() {
            return shopId;
        }

        public void setShopId(int shopId) {
            this.shopId = shopId;
        }

        public String getShopName() {
            return ShopName;
        }

        public void setShopName(String ShopName) {
            this.ShopName = ShopName;
        }

        public int getFreight() {
            return Freight;
        }

        public void setFreight(int Freight) {
            this.Freight = Freight;
        }

        public int getFreeFreight() {
            return FreeFreight;
        }

        public void setFreeFreight(int FreeFreight) {
            this.FreeFreight = FreeFreight;
        }

        public double getFullDiscount() {
            return FullDiscount;
        }

        public void setFullDiscount(double FullDiscount) {
            this.FullDiscount = FullDiscount;
        }

        public double getShopTotal() {
            return ShopTotal;
        }

        public void setShopTotal(double ShopTotal) {
            this.ShopTotal = ShopTotal;
        }

        public double getShopTotalWithoutFreight() {
            return ShopTotalWithoutFreight;
        }

        public void setShopTotalWithoutFreight(double ShopTotalWithoutFreight) {
            this.ShopTotalWithoutFreight = ShopTotalWithoutFreight;
        }

        public Object getUserBonus() {
            return UserBonus;
        }

        public void setUserBonus(Object UserBonus) {
            this.UserBonus = UserBonus;
        }

        public BaseCouponBean getOneCoupons() {
            return OneCoupons;
        }

        public void setOneCoupons(BaseCouponBean OneCoupons) {
            this.OneCoupons = OneCoupons;
        }

        public Object getFreightProductGroup() {
            return freightProductGroup;
        }

        public void setFreightProductGroup(Object freightProductGroup) {
            this.freightProductGroup = freightProductGroup;
        }

        public boolean isIsFreeFreight() {
            return IsFreeFreight;
        }

        public void setIsFreeFreight(boolean IsFreeFreight) {
            this.IsFreeFreight = IsFreeFreight;
        }

        public int getVshopId() {
            return VshopId;
        }

        public void setVshopId(int VshopId) {
            this.VshopId = VshopId;
        }

        public boolean isIsSelf() {
            return IsSelf;
        }

        public void setIsSelf(boolean IsSelf) {
            this.IsSelf = IsSelf;
        }

        public boolean isExistShopBranch() {
            return ExistShopBranch;
        }

        public void setExistShopBranch(boolean ExistShopBranch) {
            this.ExistShopBranch = ExistShopBranch;
        }

        public int getShopBranchId()
        {
            return ShopBranchId;
        }

        public void setShopBranchId(int ShopBranchId)
        {
            this.ShopBranchId = ShopBranchId;
        }

        public String getShopBranchName()
        {
            return ShopBranchName;
        }

        public void setShopBranchName(String ShopBranchName)
        {
            this.ShopBranchName = ShopBranchName;
        }

        public boolean isIsOpenLadder() {
            return IsOpenLadder;
        }

        public void setIsOpenLadder(boolean IsOpenLadder) {
            this.IsOpenLadder = IsOpenLadder;
        }

        public boolean isIsInvoice() {
            return IsInvoice;
        }

        public void setIsInvoice(boolean IsInvoice) {
            this.IsInvoice = IsInvoice;
        }

        public String getInvoiceDay() {
            return InvoiceDay;
        }

        public void setInvoiceDay(String InvoiceDay) {
            this.InvoiceDay = InvoiceDay;
        }

        public List<CartItemProductModel> getCartItemModels() {
            return CartItemModels;
        }

        public void setCartItemModels(List<CartItemProductModel> CartItemModels) {
            this.CartItemModels = CartItemModels;
        }

        public List<BaseCouponBean> getUserCoupons() {
            return UserCoupons;
        }

        public void setUserCoupons(List<BaseCouponBean> UserCoupons) {
            this.UserCoupons = UserCoupons;
        }

        public List<BaseCouponBean> getBaseCoupons() {
            return BaseCoupons;
        }

        public void setBaseCoupons(List<BaseCouponBean> BaseCoupons) {
            this.BaseCoupons = BaseCoupons;
        }

        public List<SubmitModelResult.ProductsBean.InvoiceTpyesBean> getInvoiceTpyes() {
            return invoiceTpyes;
        }

        public void setInvoiceTpyes(List<SubmitModelResult.ProductsBean.InvoiceTpyesBean> invoiceTpyes) {
            this.invoiceTpyes = invoiceTpyes;
        }

        public static class InvoiceTpyesBean {
            /**
             * Id : 2
             * Name : 电子普通发票
             * Rate : 3
             */

            private int Id;
            private String Name;
            private int Rate;

            public int getId() {
                return Id;
            }

            public void setId(int Id) {
                this.Id = Id;
            }

            public String getName() {
                return Name;
            }

            public void setName(String Name) {
                this.Name = Name;
            }

            public int getRate() {
                return Rate;
            }

            public void setRate(int Rate) {
                this.Rate = Rate;
            }
        }

        public String getRemark() {
            return remark;
        }

        public void setRemark(String remark) {
            this.remark = remark;
        }

        public InvoiceInfoParams getSimpleInvoice()
        {
            return simpleInvoice;
        }

        public void setSimpleInvoice(InvoiceInfoParams simpleInvoice)
        {
            //在此处计算 税费
            int rate = getInvoiceRateByType( this.invoiceTpyes , simpleInvoice.getInvoicetype() );
            simpleInvoice.setRate( rate );

            Float rateMoney = MoneyUtils.mul(Float.valueOf(""+ShopTotalWithoutFreight), 0.01f*rate );

            simpleInvoice.setRateMoney( String.valueOf( rateMoney ) );

            this.simpleInvoice = simpleInvoice;
        }

        public void setInvoiceInfoParams(VatInvoiceBean defInvoice , int shopId ,String invoiceDay)
        {
            InvoiceInfoParams  invoiceInfoParams = new InvoiceInfoParams();

            if( UIUtils.isNotEmpty( defInvoice ) )
            {
                // 第一次展示时  默认不选择 发票
                invoiceInfoParams.setInvoicetype(0);
                invoiceInfoParams.setInvoicecontext(defInvoice.getInvoiceContext());
                invoiceInfoParams.setName(defInvoice.getName());
                invoiceInfoParams.setCode(defInvoice.getCode());
                invoiceInfoParams.setRegisteraddress(defInvoice.getRegisterAddress());
                invoiceInfoParams.setRegisterphone(defInvoice.getRegisterPhone());
                invoiceInfoParams.setBankname(defInvoice.getBankName());
                invoiceInfoParams.setBankno(defInvoice.getBankNo());
                invoiceInfoParams.setRealname(defInvoice.getRealName());
                invoiceInfoParams.setCellphone(defInvoice.getCellPhone());
                invoiceInfoParams.setRegionid("" + defInvoice.getRegionID());
                invoiceInfoParams.setAddress(defInvoice.getAddress());
                invoiceInfoParams.setEmail(defInvoice.getEmail());
                //private String userkey;
            }

            invoiceInfoParams.setShopId( shopId );
            invoiceInfoParams.setInvoiceDay( invoiceDay );
           this.simpleInvoice = invoiceInfoParams;
        }

        // 复制店铺 商品信息
        public static SubOrderGoodsBean newSubGoodsByProduct(SubmitModelResult.ProductsBean productBean , VatInvoiceBean vatInvoiceBean)
        {
            SubOrderGoodsBean subGoodsBean = new SubOrderGoodsBean();
            subGoodsBean.setShopId( productBean.getShopId() );
            subGoodsBean.setShopName( productBean.getShopName() );
            subGoodsBean.setFreight( productBean.getFreight() );
            subGoodsBean.setFreeFreight( productBean.getFreeFreight() );
            subGoodsBean.setFullDiscount( productBean.getFullDiscount() );
            subGoodsBean.setShopTotal( productBean.getShopTotal() );
            subGoodsBean.setShopTotalWithoutFreight( productBean.getShopTotalWithoutFreight() );
            subGoodsBean.setUserBonus( productBean.getUserBonus() );
            subGoodsBean.setOneCoupons( productBean.getOneCoupons() );
            subGoodsBean.setFreightProductGroup( productBean.getFreightProductGroup() );
            subGoodsBean.setIsFreeFreight( productBean.isIsFreeFreight() );
            subGoodsBean.setVshopId( productBean.getVshopId() );
            subGoodsBean.setIsSelf( productBean.isIsSelf() );
            subGoodsBean.setExistShopBranch( productBean.isExistShopBranch() );
            subGoodsBean.setShopBranchId( productBean.getShopBranchId() );

            subGoodsBean.setShopBranchName( productBean.getShopBranchName() );
            subGoodsBean.setIsOpenLadder( productBean.isIsOpenLadder() );
            subGoodsBean.setIsInvoice( productBean.isIsInvoice() );
            subGoodsBean.setInvoiceDay( productBean.getInvoiceDay() );
            subGoodsBean.setCartItemModels( productBean.getCartItemModels() );

            subGoodsBean.setUserCoupons( productBean.getUserCoupons() );
            subGoodsBean.setBaseCoupons( productBean.getBaseCoupons() );
            subGoodsBean.setInvoiceTpyes( productBean.getInvoiceTpyes() );
            subGoodsBean.setInvoiceInfoParams(vatInvoiceBean,productBean.getShopId(), productBean.getInvoiceDay());

            return subGoodsBean;
        }


    // 获取 税率
    public static int getInvoiceRateByType(List<SubmitModelResult.ProductsBean.InvoiceTpyesBean> typeBeans , int invoiceType )
    {
        int rate = 0;
        if( UIUtils.isNotEmpty( typeBeans  ) )
        {
            for (SubmitModelResult.ProductsBean.InvoiceTpyesBean typeBean : typeBeans)
            {
                if( typeBean.getId() == invoiceType )
                {
                    rate = typeBean.getRate();
                }
            }
        }
        return rate;
    }
}
